package com.example.elderlycare.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.elderlycare.dao.entity.Visit;
import com.example.elderlycare.dao.mapper.VisitMapper;
import com.example.elderlycare.service.VisitService;
import com.example.elderlycare.service.entity.VisitItem;
import com.example.elderlycare.service.entity.VisitListResponseBody;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class VisitServiceImpl extends ServiceImpl<VisitMapper, Visit> implements VisitService {

    @Resource
    VisitMapper visitMapper;

    @Override
    public VisitListResponseBody queryVisits(Map<String, Object> params) {
        VisitListResponseBody visitListResponseBody = new VisitListResponseBody();
        int total = visitMapper.getVisitCount(params);
        visitListResponseBody.setTotal(total);
        List<Visit> visitList = visitMapper.queryVisits(params);
        List<VisitItem> items = new ArrayList<>();
        for (Visit visit : visitList) {
            VisitItem item = VisitItem.builder()
                    .id(visit.getId())
                    .name(visit.getName())
                    .certificate(visit.getCertificate())
                    .phone(visit.getPhone())
                    .number(visit.getNumber())
                    .nurseId(visit.getNurseId())
                    .nurseName(visit.getNurseName())
                    .startTime(visit.getStartTime())
                    .endTime(visit.getEndTime())
                    .certificateId(visit.getCertificateId())
                    .elderName(visit.getElderName())
                    .build();
            items.add(item);
        }
        visitListResponseBody.setVisitItemList(items);
        return visitListResponseBody;
    }
}
